
/**********************************************************************************************************************
  COPYRIGHT
-----------------------------------------------------------------------------------------------------------------------
  \par      copyright
  \verbatim
  Copyright (c) 2018 by Vector Informatik GmbH.                                                  All rights reserved.

                This software is copyright protected and proprietary to Vector Informatik GmbH.
                Vector Informatik GmbH grants to you only those rights as set out in the license conditions.
                All other rights remain with Vector Informatik GmbH.
  \endverbatim
-----------------------------------------------------------------------------------------------------------------------
  FILE DESCRIPTION
-----------------------------------------------------------------------------------------------------------------------
  \file  File:  BrsHw.h
      Project:  Vector Basic Runtime System
       Module:  BrsHw for platform NXP S32K1xx

  \brief Description:  This is the hardware specific header file for Vector Basic Runtime System (BRS).
                       This file supports: see BrsHw_DerivativeList.h

  \attention Please note:
    The demo and example programs only show special aspects of the software. With regard to the fact
    that these programs are meant for demonstration purposes only, Vector Informatik liability shall be
    expressly excluded in cases of ordinary negligence, to the extent admissible by law or statute.
**********************************************************************************************************************/

#ifndef _BRSHW_H_
#define _BRSHW_H_

/**********************************************************************************************************************
  INCLUDES
**********************************************************************************************************************/
/*
 * Description: The BrsHw_DerivativeList header contains all derivative specific settings.
 *              This file is part of the BrsHw.
 */
#include "BrsHw_DerivativeList.h"

/*
 * Description: The BrsCfg header is used to configure different types of
 *              tests and system setups. Therefore it must be included first
 *              in each BRS and test module.
 *              This file is part of the BRS.
 */
#include "BrsCfg.h"

#if !defined (BASIC_RUNTIME_SYSTEM_TYPE_MSR4)
  /*
   * Description: The v_cfg header is generated by the generation tool. It contains
   *              a list of currently used CANbedded/MSR3 modules (VGEN_ENABLE_*).
   *              For MSR4, this list is contained within VGenEnableSwitches.h of
   *              zBrs_AsrEmbeddedRunTimeSystemCfg5, included via BrsCfg.h.
   */
  #include "v_cfg.h"

  /*
   * Description: BrsTypes header is the abstraction for MSR/CBD to get access to type definitions
   */
  #include "BrsTypes.h"
#else
  /*
   * Description: Std_Types header provides all Standard Types within ASR-stacks
   */
  #include "Std_Types.h"
#endif /*BASIC_RUNTIME_SYSTEM_TYPE_MSR4*/

/*
 * Description: Inclusion of generic ARM parts
 */
#include "ARMBrsHw.h"

/**********************************************************************************************************************
  MODULE VERSION
**********************************************************************************************************************/
/*
 * Description: The version numbers are BCD coded.
 *              E.g. a main version of 1.23 is coded with 0x0123, a bug fix version of 9 is coded 0x09.
 */

/* This is the BrsHw template main and bug fix version, the platform BrsHw is reviewed to */
#define BRSHW_SOURCECODE_TEMPLATE_VERSION        0x0202u
#define BRSHW_SOURCECODE_TEMPLATE_BUGFIX_VERSION 0x02u

/* This is the BrsHw main and bug fix version */
#define BRSHW_VERSION        0x0109u
#define BRSHW_BUGFIX_VERSION 0x03u

/**********************************************************************************************************************
  GLOBAL CONSTANT MACROS
**********************************************************************************************************************/
/*
 * Description: Macro for access to IO addresses
 */
#define BRSHW_IOS(type, address) (*((volatile type *)(address)))

/**********************************************************************************************************************
  Compiler abstraction
**********************************************************************************************************************/

/**********************************************************************************************************************
  BrsHW configuration
**********************************************************************************************************************/
#if defined (BRS_OS_USECASE_OSGEN7)
/* nothing to be done here yet */

#else
  #error "Configured OS_USECASE is not supported (Organi filtered because of ALM attributes or wrong set within Makefile.config)"
#endif

/**********************************************************************************************************************
  Global variables
**********************************************************************************************************************/

/**********************************************************************************************************************
  Global const variables
**********************************************************************************************************************/
/*
 * Description: These constants are used to propagate the Versions over module boundaries.
 *              The version numbers are BCD coded. E.g. a sub version of 23 is coded with 0x23, 
 *              a bug fix version of 9 is coded 0x09.
 */
extern uint8 const kBrsHwMainVersion;
extern uint8 const kBrsHwSubVersion;
extern uint8 const kBrsHwBugfixVersion;

/**********************************************************************************************************************
  Global function prototypes
**********************************************************************************************************************/

/*****************************************************************************/
/**
 * @brief      This function has to be used to initialize the Watchdog.
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from main@BrsMain or EcuM at power on initialization
 */
/*****************************************************************************/
void BrsHwWatchdogInitPowerOn(void);

/*****************************************************************************/
/**
 * @brief      This function has to be used to initialize the PLL.
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from main@BrsMain or EcuM at power on initialization
 */
/*****************************************************************************/
void BrsHwPllInitPowerOn(void);

#if !defined (VGEN_ENABLE_DRVPORT)
# if defined (BRS_ENABLE_TCM_SUPPORT)
/* Platform specific value for TCM module TCM_CLK_OUT pin toggle measurement. */
#define BRSHW_CYCLES_PER_DELAY_LOOP 1

/*************************************
 TCM Functions
**************************************/
void BrsHw_WriteDio_TCM_CLK_OUT(uint8 Level);
void BrsHw_WriteDio_TCM_SDA_OUT(uint8 Level);
uint8 BrsHw_ReadDio_TCM_CLK_IN(void);
uint8 BrsHw_ReadDio_TCM_SDA_IN(void);
# endif /*BRS_ENABLE_TCM_SUPPORT*/
#endif /*!VGEN_ENABLE_DRVPORT*/

/*****************************************************************************/
/**
 * @brief      This function has to be used to initialize the used ports.
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from main@BrsMain or EcuM at power on initialization
 */
/*****************************************************************************/
void BrsHwPortInitPowerOn(void);

/* Wrapper from old BrsHwEvaBoardInitPowerOn() function to nothing. Done within BrsHwPortInitPowerOn() now. */
#define BrsHwEvaBoardInitPowerOn()

#if !defined (BRS_OS_USECASE_OSGEN7)  
#define BRSHW_CORTEXM_PLATFORM_SPECIFIC_NVIC_INIT
/*****************************************************************************/
/**
 * @brief      This function has to be used to initialize the used interrupts.
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from BrsHwEnableInterruptAtPowerOn or EcuM-DriverInitThree
 */
/*****************************************************************************/
void BrsHwConfigureInterruptsAtPowerOn(void);
#endif /*!BRS_OS_USECASE_OSGEN7&&!BRS_ENABLE_FBL_SUPPORT*/

/*****************************************************************************/
/**
 * @brief      restart ECU (issue a software reset or jump to startup code)
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from e.g. ECU state handling
 */
/*****************************************************************************/
void BrsHwSoftwareResetECU(void);

#if defined (BRS_ENABLE_SUPPORT_LEDS)          || \
    defined (BRS_ENABLE_SUPPORT_TOGGLE_WD_PIN) || \
    defined (BRS_ENABLE_SUPPORT_TOGGLE_CUSTOM_PIN)
typedef enum
{
  BRSHW_TOGGLEPIN_LED,
  BRSHW_TOGGLEPIN_WD,
  BRSHW_TOGGLEPIN_CUSTOM
}brsHw_TogglePin;

# if defined (BRS_ENABLE_SUPPORT_LEDS)
  /* Wrapper for old call of BrsHwSetLed() with parameter BRSHW_LED_SYSTEM_OK */
  #define BRSHW_LED_SYSTEM_OK 0 /* this is just a dummy on this platform, not used within BrsHwSetLed() */
  /* Wrapper from old BrsHwSetLed() function to new BrsHwTogglePin mechanism */
  #define BrsHwSetLed(x,y) BrsHwTogglePin(BRSHW_TOGGLEPIN_LED)
# endif /*BRS_ENABLE_SUPPORT_LEDS*/

/*****************************************************************************/
/**
 * @brief      This API is used to toggle a PortPin.
 *             Per default, the following parameters are available:
 *               BRSHW_TOGGLEPIN_LED
 *               BRSHW_TOGGLEPIN_WD
 *               BRSHW_TOGGLEPIN_CUSTOM
 *             Depending pins have to be configured within BrsHw_Ports.h.
 * @pre        -
 * @param[in]  Pin has to configure the depending pin to be toggled
 * @param[out] -
 * @return     -
 * @context    Function is called from all modules to set or clear a PortPin
 */
/*****************************************************************************/
void BrsHwTogglePin(brsHw_TogglePin Pin);

#endif /*BRS_ENABLE_SUPPORT_LEDS||BRS_ENABLE_SUPPORT_TOGGLE_WD_PIN||BRS_ENABLE_SUPPORT_TOGGLE_CUSTOM_PIN*/

# if defined (BRSASR_ENABLE_SAFECTXSUPPORT)
/*****************************************************************************/
/**
 * @brief      This API is used to enable hardware access in untrusted mode
 * @pre        -
 * @param[in]  -
 * @param[out] -
 * @return     -
 * @context    Function is called from BrsAsrInitBsw
 */
/*****************************************************************************/
void BrsHw_EnableHwAccess(void);
# endif /*BRSASR_ENABLE_SAFECTXSUPPORT*/

/**********************************************************************************************************************
  Interrupt handler function protoytpes
**********************************************************************************************************************/

#endif /*_BRSHW_H_*/
